﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace BloodThirsty
{
    public class GameSprite
    {
        private Texture2D[] _texture2D;

        public Texture2D[] Texture2D
        {
            get { return _texture2D; }
            set { _texture2D = value; }
        }

        private float _x;

        public virtual float X
        {
            get { return _x; }
            set { _x = value; }
        }

        private float _y;

        public virtual float Y
        {
            get { return _y; }
            set { _y = value; }
        }

        private int _iTexture2D;

        public int iTexture2D
        {
            get { return _iTexture2D; }
            set { _iTexture2D = value; }
        }

        private int _nTexture2D;

        public int nTexture2D
        {
            get { return _nTexture2D; }
            set { _nTexture2D = value; }
        }

        private float _xOffset;

        public float xOffset
        {
            get { return _xOffset; }
            set { _xOffset = value; }
        }

        private float _yOffset;

        public float yOffset
        {
            get { return _yOffset; }
            set { _yOffset = value; }
        }

        private int _nDelay;

        public int nDelay
        {
            get { return _nDelay; }
            set { _nDelay = value; }
        }

        private int _check;

        public int Check
        {
            get { return _check; }
            set { _check = value; }
        }

        public GameSprite(Texture2D[] inputTexture2D, float inputX, float inputY)
        {
            this.Texture2D = inputTexture2D;
            this.nTexture2D = inputTexture2D.Length;
            this.iTexture2D = 0;
            this.X = inputX;
            this.Y = inputY;
            this.Check = this.nDelay;
        }

        public GameSprite(Texture2D inputTexture2D, float inputX, float inputY)
        {
            this.Texture2D = new Texture2D[1];
            this.Texture2D[0] = inputTexture2D;
            this.nTexture2D = 1;
            this.iTexture2D = 0;
            this.X = inputX;
            this.Y = inputY;
            this.Check = this.nDelay;
        }

        public void Update(GameTime gametime)
        {
            if (this.Check == 0)
            {
                this.iTexture2D = (this.iTexture2D + 1) % this.nTexture2D;
                this.Check = this.nDelay;
            }
            else
            {
                this.Check = -1;
            }
        }

        public void Draw(GameTime gametime, SpriteBatch spritebatch)
        {
            spritebatch.Draw(this.Texture2D[this.iTexture2D], new Vector2(this.X + GlobalVariables.dX
                            + this.xOffset, this.Y + GlobalVariables.dY + this.yOffset), Color.White);
        }

        public GameSprite Clone()
        { 
            return new GameSprite(this.Texture2D,this.X,this.Y)
            {
                Texture2D=this.Texture2D,
                iTexture2D=this.iTexture2D,
                nTexture2D=this.nTexture2D,
                X=this.X,
                Y=this.Y,
                xOffset=this.xOffset,
                yOffset=this.yOffset,
                nDelay=this.nDelay,
                Check=this.Check,
            };
        }
    }
}
